#03_pygame库 draw

import pygame
from pygame.locals import *
from sys import exit
from random import *

__author__ = {'name' : 'Hongten',
              'mail' : 'hongtenzone@foxmail.com',
              'blog' : 'http://www.cnblogs.com/hongten',
              'Version' : '1.0'}

pygame.init()

SCREEN_WIDTH = 500
SCREEN_HEIGHT = 500
SCREEN_DEFAULT_SIZE = (SCREEN_WIDTH, SCREEN_HEIGHT)
SCREEN_DEFAULT_COLOR = (0, 0 ,0)
#record the mouse clicked points
RECORD = True

screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32)
screen.fill(SCREEN_DEFAULT_COLOR)

def draw_lines(screen, line_color, points, mouse_pos):
    for point in points:
        pygame.draw.line(screen, line_color, point, mouse_pos)
ps = []
#you can add other points
points = [(0, 0), (250, 0), (500, 0),
          (0, 250),(0, 500),(250, 500),
          (500, 250),(500, 500)]


while 1:
    for event in pygame.event.get():
        if event.type ==  QUIT:
            exit()
        elif event.type == KEYDOWN:
            screen.fill(SCREEN_DEFAULT_COLOR)
        elif event.type == MOUSEMOTION:
            screen.fill(SCREEN_DEFAULT_COLOR)
            line_color = (randint(0, 255), randint(0, 255), randint(0, 255))
            draw_lines(screen, line_color, points, pygame.mouse.get_pos())
            #record the mouse clicked points depend on yourself
            if not RECORD:
                ps = []
            for c_p in ps:
                draw_lines(screen, c_p[0], points, c_p[1])  
        elif event.type == MOUSEBUTTONDOWN:
            x, y = pygame.mouse.get_pos()
            line_color = (randint(0, 255), randint(0, 255), randint(0, 255))
            draw_lines(screen, line_color, points, (x, y))
            ps.append((line_color, (x, y)))
            
    pygame.display.update()
